package com.banyuan.aop;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author yzt
 */
@Component
@Aspect
public class LogAop {

    private static final Logger logger = LogManager.getLogger("用户操作日志");


    @Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public void getPointcut() {
    }

    @Before("getPointcut()")
    public void log(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs(); //参数
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().getName();

        logger.info("正在访问{}类的 {}方法 传入的参数为{}",className,methodName,args);
    }
}
